<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('课程列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId" class="form-inline">
            <input type="text" class="form-control mr-1" name="courseName" placeholder="请输入课程名称...">
            <button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
                <i class="fa fa-search"></i>
                搜索
            </button>
            <button type="button" class="btn btn-default" onclick="$.form.reset()">
                <i class="fa fa-refresh"></i>
                重置
            </button>
        </form>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var sellTypeDatas = [[${@dict.getType('qdx_course_type')}]];

    $(function() {
        var options = {
            url: "/course/select/list.json",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            modalName: "课程",
            columns: [{
                checkbox: true
            },
                {
                    field: 'courseId',
                    title: 'id'
                },
                {
                    field: 'courseName',
                    title: '名称'
                },
                {
                    field: 'sellType',
                    title: '类型',
                    formatter: function (value, row, index) {
                        if (value === "COURSE") {
                            return $.table.selectDictLabel(sellTypeDatas, value);
                        } else if (value === "LIVE") {
                            return '<span style="color: #2798C8">' + $.table.selectDictLabel(sellTypeDatas, value) + '</span>'
                        } else if (value === "PACKAGE") {
                            return '<span style="color:red;">' + $.table.selectDictLabel(sellTypeDatas, value) + '</span>'
                        }
                    }
                },
                {
                    field: 'categoryName',
                    title: '专业'
                },
                {
                    field: 'price',
                    title: '价格', formatter(value, row, index) {
                        return value / 100 + ' 元';
                    }
                }]
        };
        $.table.init(options);
    });

    function submitHandler() {
        table.set();
        var rowss = $('#bootstrap-table').bootstrapTable('getSelections');//行的数据
        if (rowss.length === 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var courseArr = [];
        for (var i = 0; i < rowss.length; i++) {
            var tcId = rowss[i].courseId;
            var tcName = rowss[i].courseName;
            var tc = {'courseId': tcId, 'courseName': tcName};
            courseArr.push(tc);
        }
        window.parent.courseList(courseArr);
        window.parent.layer.closeAll();
    }

</script>
</body>
</html>